
/*
 * @Autor: Mr Lu
 * @Version: 1.0
 * @Date: 2019-12-03
 * @LastEditors: OBKoro1
 * @LastEditTime: 2019-12-03
 * @Description:  预警信息
 * 组件说明：树形组件
  itemActive:是否需要高亮显示  Boolean
  data:树形组件的数据 Array类型
  props:组件属性  Object {id:'',children:'',name:''}
  lazy:是否开启懒加载 Boolean 
  @load:懒加载回调方法 Funciton  返回当前点击项的所有数据
  @click:点击事件方法 Funciton 返回当前点击项的所有数据
  clickableConditions: 可以点击的条件 Object
    {
        //所有的列表是否可以点击
        all: {
          enable: true
        },

      //部分的列表可以点击 
      //以下条件说明【 orgType = 1或orgType = 2时可以点击】
      part: {
        prop: "orgType", 
        value: [1,2]
      }
    },
 */
<template>
  <div id="WarningMessage" class="p-box">
    <div class="p-return">
      <mu-appbar color="primary" class="lan-header">
        <mu-button icon slot="left" v-close>
          <i class="iconfont angle-left iconangle-left"></i>
          <span class="lan-header-back">返回</span>
        </mu-button>预警信息
      </mu-appbar>
    </div>
    <div class="p-content">
      <wallModule name="预警总计(个)" :total="totalCount" :bgImage="wallBgImage" />
      <div class="t-box">
        <div class="t-title">质量检查</div>
        <div class="t-content">
          <div class="t-header">
            <span class="name">超期未整改</span>
            <span class="total">{{totalCount}}</span>
          </div>
          <div class="t-body">
            <mTree
              v-show="tree.data.length"
              :data="tree.data"
              :props="tree.defaultProps"
              :lazy="true"
              @load="loadData"
              :clickableConditions="tree.clickableConditions"
              @click="skipPage"
              :showTotal="true"
            ></mTree>
            <NoData v-if="!tree.data.length&&!tree.loading" />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import WeatherModule from "@/weather/WeatherModule";
import wallModule from "@/wall/wallModule";
import mTree from "@/tree/mTree";
export default {
  name: "WarningMessage",
  components: {
    WeatherModule,
    mTree,
    wallModule
  },
  data() {
    return {
      totalCount: 0,
      overflowDateCount: 0,
      wallBgImage: require("#/assets/img/wall/wall.png"),
      tree: {
        loading: false,
        defaultProps: {
          id: "orgId",
          name: "orgName",
          children: "children"
        },
        clickableConditions: {
          all: {
            //所有的是否可以点击
            enable: false
          },
          part: {
            //部分的可以点击的条件
            prop: "orgType",
            value: [1]
          }
        },
        data: []
      }
    };
  },
  computed: {},
  created() {
    this.initPage();
  },
  mounted() {},
  watch: {},
  methods: {
    skipPage(treeRowData) {
      this.$router.push({
        name: "warringParameter",
        query: {
          orgId: treeRowData.orgId,
          label: treeRowData.orgName,
          type: treeRowData.orgType
        }
      });
    },
    initPage() {
      this.getTotal();
      let params = {
        orgId: this.$A.GS("orgInfo")["orgId"],
        type: this.$A.GS("orgInfo")["type"],
        alarmStatus: 2
      };

      this.getData(params).then(response => {
        if (response.code == 200) {
          this.tree.data =
            response.body && response.body.length ? response.body : [];
        } else {
          this.tree.data = [];
        }
      });
    },
    getTotal() {
      let params = {
        orgId: this.$A.GS("orgInfo")["orgId"],
        type: this.$A.GS("orgInfo")["type"]
      };
      this.$A.Go("get", "/safety/qualityTotalAlarm/statistic", params).then(
        response => {
          if (response.code == 200) {
            this.totalCount = response.body.totalAlarmCount;
          }
        },
        err => {
          console.log(err);
        }
      );
    },
    loadData(treeRowData) {
      let params = {
        orgId: treeRowData.orgId,
        type: treeRowData.orgType,
        alarmStatus: 2
      };
      this.getData(params).then(response => {
        if (response.code == 200) {
          if (response.body && response.body.length) {
            var newArray = response.body;
            newArray.forEach(element => {
              element.level = treeRowData.level + 1;
            });
            this.$set(treeRowData, "children", newArray);
            this.$set(treeRowData, "expanded", true);
          } else {
            this.$set(treeRowData, "isLeaf", true);
          }
        } else {
        }
      });
    },
    getData(params) {
      this.$openLoading();
      this.tree.loading = true;
      let p = new Promise((resolve, reject) => {
        this.$A.Go("post", "/safety/importantRectLayer/statistic", params).then(
          response => {
            this.$closeLoading();
            this.tree.loading = false;
            resolve(response);
          },
          err => {
            this.$closeLoading();
            this.tree.loading = false;
            console.log(err);
          }
        );
      });
      return p;
    }
  },
  destroyed() {}
};
</script>

<style lang="scss">
#WarningMessage {
}
</style>
